<template>
	<view class="withdrawal-type">
		<g-navbar title="提现至" />
		<view class="withdrawal-type-list">
			<view class="withdrawal-type-item" v-for="item,index in withdrawal_type_list" :key="index"
				:class="{'current':currentWithdrawalType.type === item.type}" @click="selectWithdrawalType(item.key)">
				<image :src="item.icon" class="icon" />
				<view class="text">
					{{item.value}}
				</view>
				<view class="current-icon" v-if="currentWithdrawalType.type === item.type">
					<i class="iconfont icon-current" />
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import global from '@/global';
	import type { IWithdrawalType } from '@/global';
	import { WITHDRAWAL_TYPE__KEY } from '@/enum/withdrawal';
	import { ref, Ref } from "vue";
	import { onLoad } from '@dcloudio/uni-app'


	const withdrawal_type_list = global.withdrawal_type_list;

	const currentWithdrawalType : Ref<IWithdrawalType> = ref(withdrawal_type_list[WITHDRAWAL_TYPE__KEY.WECHAT]);




	onLoad((e) => {
		currentWithdrawalType.value = withdrawal_type_list[(e.current as WITHDRAWAL_TYPE__KEY)]
	})


	const selectWithdrawalType = (value : WITHDRAWAL_TYPE__KEY) => {
		currentWithdrawalType.value = global.withdrawal_type_list[value];
		uni.navigateBack({
			success: () => {
				uni.$emit('updateWithdrawalType',value)
				// setTimeout(() => {
				// 	const prepages = getCurrentPages()[getCurrentPages()
				// 		.length - 1];
				// 	console.log('prepages>>>>>>>>>>>>>>>>>>>>', prepages);
				// 	prepages.$.$pageInstance
				// 		.setupState.selectWithdrawalType(value)
				// }, 100)
			}

		})
	}
</script>

<style scoped lang="scss">
	@import "./withdrawalType.scss";
</style>